package utils;

import javafx.scene.control.TextArea;
import org.apache.ibatis.session.SqlSession;
import org.testng.annotations.Test;

public class EmployeeTest {

    @Test
    public <sqlSession, Emloyee> void findEmployeeByIdTest(){
     sqlSession sqlsession = MyBatisUtils.getSession();
     Emloyee emloyee = sqlsession.selectOne("selectByPrimarKey",3);
        System.out.println(emloyee.toString());
    }
    @Test
    public <sqlSession, Employee> void addEmployeeTest(){
        sqlSession sqlSession = MyBatisUtils.getSession();
        Employee employee = new Employee();
        employee.setId(4);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");
        int addInt = sqlSession.insert("insert",employee);
        sqlSession.commit();// 提交事务
        sqlSession.close();// 关闭链接
        System.out.println(addInt);
    }
    @Test
    public <Employee> void updateByPrimaryKey() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Employee employee = new Employee();
        employee.setId(2);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");
        int u = sqlSession.update("updateByPrimaryKey", employee);
        sqlSession.commit();// 提交事务
        sqlSession.close();// 关闭链接
        System.out.println(u);
    }
        @Test
                public void  deleteEmployeeById(){
            SqlSession session = MyBatisUtils.getSession();
            int d = sqlSession.delete("deleteByPrimaryKey",1L);
            sqlSession.commit();// 提交事务
            System.out.println(d);// 关闭链接
            System.out.println(d);
        }
    }
}
